<template>
  修改密码
  <el-form ref="form" :model="form">
    <el-form-item label="输入原始密码">
      <el-input v-model="form.ypassword" type="password"></el-input>
    </el-form-item>
    <el-form-item label="输入新密码">
      <el-input v-model="form.password" type="password"></el-input>
    </el-form-item>
    <el-form-item label="再次输入新密码">
      <el-input v-model="form.npassword" type="password"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" round @click="uppwd">提交修改</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { ElMessage } from "element-plus";
export default {
  props: ["jwttoken"],
  name: "editpwd",
  data() {
    return {
      form: { ypassword: "", password: "", npassword: "" },
    };
  },
  methods: {
    uppwd: function () {
      if (this.form.ypassword == "") {
        ElMessage.warning({
          message: "请输入原始密码",
          type: "warning",
        });
        return false;
      }
      if (this.form.password == "") {
        ElMessage.warning({
          message: "请输入新密码",
          type: "warning",
        });
        return false;
      }
      if (this.form.npassword == "") {
        ElMessage.warning({
          message: "请再次输入新密码",
          type: "warning",
        });
        return false;
      }
      if (this.form.password != this.form.npassword) {
        ElMessage.warning({
          message: "两次密码输入的不一样",
          type: "warning",
        });
        return false;
      }
      let that = this;
      this.$jquery.ajax({
        async: false,
        type: "POST",
        url: that.$baseurl + "updatePwd",
        dataType: "json",
        beforeSend: function (request) {
          request.setRequestHeader("Authorization", that.jwttoken);
        },
        data: {
          ypassword: that.form.ypassword,
          password: that.form.password,
          npassword: that.form.npassword,
        },
        success: function (rtn) {
          if (rtn.code == -5) {
            that.$emit("loginstate1", -1);
          }
          if (rtn.code == 1) {
            ElMessage.success({
              message: "修改成功",
              type: "success",
            });
            setTimeout(() => {
                location.reload()
            }, 1000);
          } else {
            ElMessage.error(rtn.msg);
          }
        },
      });
    },
  },
};
</script>